Ubuntu 14.04
Sponsored Link

JDK 8 : Install
2016/01/20
 
Install Java SE Development Kit 8 (JDK8) and build Java Environment.
[1] Download and install JDK 8.
Make sure the latest version and source URL of JDK on Oracle download site.
root@dlp:~#
curl -LO -H "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/8u71-b15/jdk-8u71-linux-x64.tar.gz"
root@dlp:~#
tar zxvf jdk-8u71-linux-x64.tar.gz

root@dlp:~#
mkdir /usr/java

root@dlp:~#
mv jdk1.8.0_71 /usr/java/jdk1.8.0_71
root@dlp:~#
vi /etc/profile
# add follows to the end

export JAVA_HOME=/usr/java/jdk1.8.0_71
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
root@dlp:~#
source /etc/profile
[2] If another version of JDK had been installed, change the default like follows.
root@dlp:~#
update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.8.0_71/bin/java" 1

root@dlp:~#
update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.8.0_71/bin/javac" 1

root@dlp:~#
update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.8.0_71/bin/javaws" 1
root@dlp:~#
update-alternatives --config java

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /usr/java/jdk1.8.0_71/bin/java                   1         manual mode
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode

# select the latest one
Press enter to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/java/jdk1.8.0_71/bin/java to provide /usr/bin/java (java) in manual mode

# change like above, too

root@dlp:~#
update-alternatives --config javac

root@dlp:~#
update-alternatives --config javaws

[3] Create a test program and make sure if it works normally.
root@dlp:~#
vi day.java
import java.util.Calendar;

class day {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day = cal.get(Calendar.DATE);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        System.out.println(year + "/" + month + "/" + day + " " + hour + ":" + minute);
    }
}

root@dlp:~#
javac day.java
   
# compile

root@dlp:~#
java day
   
# run

2016/1/18 19:13
 
Tweet